import Taro from '@tarojs/taro'
import {View, Text,} from '@tarojs/components';
import {AtIcon} from 'taro-ui'
import "taro-ui/dist/style/components/button.scss"
import './fenlei.less'
import {useEffect, useState} from 'react'
import http from "../../../service/api";
import store from "../../../store";


const FenLei = () => {
    const [name, setName] = useState([
    ])
    useEffect(()=>{
        Taro.request({
            url: http.api2 + "/classification/findFirstClasses",
            method: "post",
            header: {
                'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            success(res) {
               console.log(res)
                setName(res.data.firstClasses)
            },
            fail(err) {
                console.log("失败了")
            }
        })
    },[])
   
    const click=(item)=>{
        store.setFirstType(item)
        Taro.navigateTo({
            url: "../fenleiList/fenleiList"
        })
    }
    return (
        <View className='type'>
            <Text className='header'>分类</Text>
            <View className="list">
                {name.map((item, index) => {
                    return (
                        <View className="data" key={index} onClick={()=>{click(item)}}>
                            <View className='icon at-icon at-icon-bookmark'/>
                            <View className="name">{item.name}</View>
                        </View>
                    )
                })}
            </View>
        </View>
    )
}
export default FenLei;
